﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Newtonsoft.Json;
using Power.Common;
using Power.Models;
using Power.View;
using Power.View.Dialog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel
{
    public class AIReviewViewModel : ViewModelBase
    {
        /// <summary>
        /// 图片地址
        /// </summary>
        public static string imgSrc = "/Resources/images/";

        private AIReview model;
        public AIReviewViewModel(AIReview model)
        {
            this.model = model;
            TabSwitch = new RelayCommand<object>(OnTabSwitch);
            AddExcel = new RelayCommand(OnAddExcel);
            DelExcel = new RelayCommand(OnDelExcel);
            ToReview = new RelayCommand<object>(OnToReview);
            CheckBoxClick = new RelayCommand<object>(OnCheckBoxClick);
            Delete = new RelayCommand(OnDelete);
            BatchDistinguish = new RelayCommand(OnBatchDistinguish);
            //datagrid绑定行数据加载事件
            this.model.SectionDataGrid1.LoadingRow += SectionDataGrid1_LoadingRow;
            Data = new AIReviewEntity
            {
                //原缺陷类别
                CategorySelectList = Common.Common.GetDefectNameSelectList(),
                //原缺陷等级
                LevelSelectList = Common.Common.GetDefectLevel1SelectList(),
                //AI识别缺陷类别
                AICategorySelectList = Common.Common.GetDefectNameSelectList(),
                //AI识别缺陷等级
                AILevelSelectList = Common.Common.GetDefectLevel1SelectList(),
                Other = "其他"
            };
            if (StaticCache.ExcelList != null) {
                Data.ExcelList = InitExcelList(StaticCache.ExcelList);
            }
            this.model.ComboboxCategory.SelectionChanged += ComboboxCategory_SelectionChanged;
            this.model.ComboboxLevel.SelectionChanged += ComboboxLevel_SelectionChanged;
            this.model.ComboboxAICategory.SelectionChanged += ComboboxAICategory_SelectionChanged;
            this.model.ComboboxAILevel.SelectionChanged += ComboboxAILevel_SelectionChanged;
        }

        //ai等级
        private void ComboboxAILevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedData();
        }

        //ai分类
        private void ComboboxAICategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedData();
        }

        //等级
        private void ComboboxLevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedData();
        }

        //分类
        private void ComboboxCategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedData();
        }

        //下拉框筛选
        public void SelectedData() {
            if (this.Data.ExcelList == null || this.Data.ExcelList.Count < 1) {
                return;
            }
            var item = GetCurExcelItem();
            if (item != null) {
                List<DataList> dataList = new List<DataList>();
                dataList = StaticCache.AiDic[item.Id];
                var category = (SelectListItem)this.model.ComboboxCategory.SelectedItem;
                if (category != null && category.SelectItem != "全部") {
                    dataList = dataList.Where(a => a.PriDefect.Name == category.SelectItem).ToList();
                }
                var level = ((SelectListItem)this.model.ComboboxLevel.SelectedItem);
                if (level != null && level.SelectItem != "全部")
                {
                    int iLevel = Convert.ToInt32(level.SelectItem);
                    dataList = dataList.Where(a => a.PriDefect.Level == iLevel).ToList();
                }
                var aiCategory = (SelectListItem)this.model.ComboboxAICategory.SelectedItem;
                if (aiCategory != null && aiCategory.SelectItem != "全部")
                {
                    dataList = dataList.Where(a => a.AIDefect != null && a.AIDefect.Name == aiCategory.SelectItem).ToList();
                }
                var aiLevel = (SelectListItem)this.model.ComboboxAILevel.SelectedItem;
                if (aiLevel != null && aiLevel.SelectItem != "全部")
                {
                    int iAiLevel = Convert.ToInt32(aiLevel.SelectItem);
                    dataList = dataList.Where(a => a.AIDefect != null && a.AIDefect.Level == iAiLevel).ToList();
                }
                this.Data.DataListList = new ObservableCollection<DataList>(dataList);
            }
        }

        //复核模式
        private void OnToReview(object dataId)
        {
            if (StaticCache.ExcelList == null) {
                MessagePrompt box1 = new MessagePrompt("请添加Excel");
                box1.ShowDialog();
                return;
            }
            //获取当前选中的工作区
            var item = GetCurExcelItem();
            if (item != null)
            {
                var model = new AIReviewDetail($"{dataId}",this.model, item);
                ((Window.GetWindow(this.model) as MainWindow).DataContext as MainViewModel).UserContent = model;
            }
        }

        /// <summary>
        /// 添加Excel
        /// </summary>
        private void OnAddExcel()
        {
            System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = folderBrowserDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK || result == System.Windows.Forms.DialogResult.Yes)
            {
                var photoPath = "";
                var par = Directory.GetParent(folderBrowserDialog.SelectedPath);
                //获取照片目录
                photoPath = par.GetDirectories("photo", SearchOption.TopDirectoryOnly).FirstOrDefault()?.FullName;

                StaticCache.AiDic = new Dictionary<string, List<DataList>>();
                StaticCache.AiDicPic = new Dictionary<string, List<PicturesInfo>>();
                var files = Directory.GetFiles(folderBrowserDialog.SelectedPath).ToList();
                List<WorkSpaceEntity> list = new List<WorkSpaceEntity>();
                int index = 1;
                foreach (var item in files)
                {
                    FileInfo fileInfo = new FileInfo(item);
                    if (fileInfo.Extension.ToLower() != ".xls" && fileInfo.Extension.ToLower() != ".xlsx") continue;
                    var workSpace = new WorkSpaceEntity() { Id = index.ToString(), Name = fileInfo.Name, LocalFile = item };
                    list.Add(workSpace);
                    var resultRead = ReadExcel(workSpace.LocalFile);
                    List<DataList> dataList = resultRead.DataList;
                    for (int i = 0; i < dataList.Count; i++)
                    {
                        var imgItem = dataList[i];
                        if (resultRead.PicList != null && resultRead.PicList.Count > 0)
                        {
                            break;
                        }
                        string imageSrc = photoPath + $"\\{imgItem.ImagesName}.jpg";
                        if (!File.Exists(imageSrc))
                        {
                            //图片不存在不加载该条数据
                            dataList.Remove(imgItem);
                            i--;
                        }
                        else
                        {
                            imgItem.ImagesSrc = imageSrc;
                        }
                    }
                    
                    StaticCache.AiDic.Add(workSpace.Id, dataList);
                    StaticCache.AiDicPic.Add(workSpace.Id, resultRead.PicList);
                    index++;
                    
                }

                if (list.Count > 0) { 
                    StaticCache.ExcelList = list;
                    Data.ExcelList = InitExcelList(StaticCache.ExcelList);
                }
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        private void OnDelete()
        {
            if (StaticCache.ExcelList == null)
            {
                MessagePrompt box1 = new MessagePrompt("请添加Excel");
                box1.ShowDialog();
                return;
            }
            var selectedList = Data.DataListList.Where(p => p.IsChecked == true).ToList();
            if (selectedList == null || selectedList.Count == 0)
            {
                MessagePrompt box = new MessagePrompt("请选择要删除的行");
                box.ShowDialog();
                return;
            }
            {
                MessagePrompt box = new MessagePrompt("是否确认删除？", true);
                var result = box.ShowDialog();
                if (result == true)
                {
                    var curExcelItem = GetCurExcelItem();
                    if (curExcelItem != null)
                    {
                        List<DataList> itemList = new List<DataList>();
                        itemList = StaticCache.AiDic[curExcelItem.Id];
                        List<PicturesInfo> picList = StaticCache.AiDicPic[curExcelItem.Id];
                        foreach (var item in selectedList)
                        {
                            if (picList != null && picList.Count > 0)
                            {
                                int index = itemList.IndexOf(item);
                                itemList.Remove(item);
                                picList.RemoveAt(index);
                            }
                            else { 
                                itemList.Remove(item);
                            }
                        }
                        this.CheckBoxIsChecked = false;
                        this.Data.DataListList = new ObservableCollection<DataList>(itemList);
                    }
                }
            }
        }

        /// <summary>
        /// 批量识别
        /// </summary>
        private void OnBatchDistinguish()
        {
            if (StaticCache.ExcelList == null || StaticCache.ExcelList.Count < 1) {
                MessagePrompt box1 = new MessagePrompt("请添加Excel");
                box1.ShowDialog();
                return;
            }
            var selectedList = Data.DataListList.Where(p => p.IsChecked == true).ToList();
            if (selectedList == null || selectedList.Count == 0)
            {
                MessagePrompt box1 = new MessagePrompt("请选择要识别的行");
                box1.ShowDialog();
                return;
            }
            //获取当前excel
            var curItem = GetCurExcelItem();
            List<PicturesInfo> picList = StaticCache.AiDicPic[curItem.Id];
            //获取照片目录
            foreach (var item in selectedList)
            {
                var inputItem = StaticCache.AiDic[curItem.Id].FirstOrDefault(a => a.Id == item.Id);
                byte[] imageBytes = null;
                if (picList == null || picList.Count < 1) //判断是否为第二套模板
                {
                    if (!File.Exists(item.ImagesSrc))
                    {
                        MessagePrompt msg = new MessagePrompt($"未能找到，序号{item.Id}的检查图片，请确认路径图片名称是否正确");
                        msg.ShowDialog();
                        return;
                    }
                    imageBytes = Common.Common.GetImagesBytes(item.ImagesSrc);
                }
                else {
                    imageBytes = picList.ElementAtOrDefault(StaticCache.AiDic[curItem.Id].IndexOf(inputItem))?.PictureData;
                }
                string resultStr = DistinguishReulst(imageBytes);
                if (!string.IsNullOrWhiteSpace(resultStr))
                {
                    inputItem.AIDefect = JsonConvert.DeserializeObject<DefectEntity>(resultStr);
                }
            }
            this.Data.DataListList = new ObservableCollection<DataList>(StaticCache.AiDic[curItem.Id]);
            //防止选中色覆盖
            this.model.SectionDataGrid1.SelectedIndex = -1;
            MessagePrompt box = new MessagePrompt("操作成功");
            box.ShowDialog();
            this.CheckBoxIsChecked = false;
        }

        /// <summary>
        /// 删除Excel
        /// </summary>
        private void OnDelExcel()
        {
            if (StaticCache.ExcelList == null)
            {
                MessagePrompt box1 = new MessagePrompt("请添加Excel");
                box1.ShowDialog();
                return;
            }
            var item = GetCurExcelItem();
            MessagePrompt box = new MessagePrompt("是否删除Excel？", true);
            if (box.ShowDialog() == true) {
                if (item != null)
                {
                    StaticCache.ExcelList.Remove(item);
                    StaticCache.AiDic.Remove(item.Id);
                    StaticCache.AiDicPic.Remove(item.Id);
                    //初始化，选中第一个
                    this.Data.ExcelList = InitExcelList(StaticCache.ExcelList);
                }
            }
        }

        /// <summary>
        /// 页面切换
        /// </summary>
        /// <param name="sender"></param>
        private void OnTabSwitch(object sender)
        {
            string imgSrc = "/Resources/images/";
            Button curButton = (Button)sender;
            this.CheckBoxIsChecked = false;
            foreach (var item in Data.ExcelList)
            {
                if (item.Id == curButton.Tag.ToString())
                {
                    //设置选中
                    item.ImageSrcConLeft = $"{imgSrc}dcl11.png";
                    item.ImageSrcConRight = $"{imgSrc}dcl99.png";
                    item.BorderBackground = "#0087D3";
                    item.LabelForeground = "#FFFFFF";
                    if (StaticCache.AiDic.ContainsKey(item.Id))
                    {
                        this.Data.DataListList = new ObservableCollection<DataList>(StaticCache.AiDic[item.Id]);
                    }
                }
                else
                {
                    item.ImageSrcConLeft = $"{imgSrc}dcl1.png";
                    item.ImageSrcConRight = $"{imgSrc}dcl9.png";
                    item.BorderBackground = "Transparent";
                    item.LabelForeground = "#7C8288";
                }
            }
        }

        /// <summary>
        /// 控制行变色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SectionDataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            var data = (DataList)e.Row.Item;
            if (data.AIDefect != null)
            {
                if (!string.IsNullOrWhiteSpace(data.AIDefect.Name) && data.PriDefect.Name != data.AIDefect.Name)
                {
                    DataGridRow row = e.Row;
                    row.Foreground = new SolidColorBrush(Colors.Red);
                    row.Background = new SolidColorBrush(Color.FromRgb(254, 242, 242));
                }
                else if (data.AIDefect.Level != -1 && data.PriDefect.Level != data.AIDefect.Level)
                {
                    DataGridRow row = e.Row;
                    row.Foreground = new SolidColorBrush(Color.FromRgb(240, 160, 102));
                    row.Background = new SolidColorBrush(Color.FromRgb(255, 248, 238));
                }
            }
        }

        private void OnCheckBoxClick(object obj)
        {
            var item = Data.DataListList.Where(p => p.Id == obj.ToString()).FirstOrDefault();
            if (item != null)
            {
                item.IsChecked = !item.IsChecked;
            }
        }

        private bool checkBoxIsChecked;
        public bool CheckBoxIsChecked
        {
            get
            {
                return checkBoxIsChecked;
            }
            set
            {
                checkBoxIsChecked = value;
                ChangedSelecgedFlags();
                RaisePropertyChanged();
                RaisePropertyChanged("Data.DataList");
            }
        }

        private void ChangedSelecgedFlags()
        {
            foreach (var e in Data.DataListList)
                e.IsChecked = CheckBoxIsChecked;
        }

        private (List<DataList> DataList, List<PicturesInfo> PicList) ReadExcel(string filePath)
        {
            List<DataList> dataList = new List<DataList>();
            var result = ExcelHelper.ReadExcel(filePath);
            var dataTable = result.DataTable;
            if (dataTable != null)
            {
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    if (!dataTable.Columns.Contains("起始井号"))
                    {
                        break;
                    }

                    DataList item = new DataList();
                    if (result.PicList != null && result.PicList.Count > 0)
                    {
                        item.Id = dataTable.Rows[i]["RowNum"].ToString();
                    }
                    else
                    {
                        item.Id = (i + 1).ToString();
                    }
                    
                    if (dataTable.Columns.Contains("检测描述"))
                    {
                        item.Remark = dataTable.Rows[i]["检测描述"].ToString();
                    }
                    
                    item.PriDefect = new DefectEntity();

                    if (dataTable.Columns.Contains("缺陷代码"))
                    {
                        item.PriDefect.Code = dataTable.Rows[i]["缺陷代码"].ToString();
                        item.PriDefect.Type = GetDefectTypeByCode(item.PriDefect.Code);
                        item.PriDefect.Name = GetDefectNameByCode(item.PriDefect.Code);

                    }
                    if (dataTable.Columns.Contains("缺陷位置"))
                    {
                        item.PriDefect.CircleDirection = GetCircleDirection(dataTable.Rows[i]["缺陷位置"].ToString());
                        item.PriDefect.Describe = item.Remark;
                    }

                    if (dataTable.Columns.Contains("缺陷等级"))
                    {
                        int le = 0;
                        int.TryParse(dataTable.Rows[i]["缺陷等级"].ToString(), out le);
                        item.PriDefect.Level = le == 0 ? null: (int?)le ;
                    }
                    if (dataTable.Columns.Contains("检测图片"))
                    {
                        if (result.PicList != null && result.PicList.Count > 0)
                        {
                            item.ImagesName = (i + 1).ToString();
                        }
                        else
                        {
                            item.ImagesName = dataTable.Rows[i]["检测图片"].ToString();
                        }
                        

                    }
                    else
                    {
                        item.ImagesName = (i + 1).ToString();
                    }
                    item.StartWell = new WellEntity();
                    if (dataTable.Columns.Contains("起始井号"))
                    {
                        item.StartWell.No = dataTable.Rows[i]["起始井号"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.StartWell.No))
                    {
                        item.StartWell.No = "-";
                    }

                    if (dataTable.Columns.Contains("起始井类型"))
                    {
                        item.StartWell.Type = dataTable.Rows[i]["起始井类型"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.StartWell.Type))
                    {
                        item.StartWell.Type = "-";
                    }

                    if (dataTable.Columns.Contains("起始井功能类型"))
                    {
                        item.StartWell.FuncType = dataTable.Rows[i]["起始井功能类型"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.StartWell.FuncType))
                    {
                        item.StartWell.FuncType = "-";
                    }
                    if (dataTable.Columns.Contains("起始井材质"))
                    {
                        item.StartWell.Mat = dataTable.Rows[i]["起始井材质"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.StartWell.Mat))
                    {
                        item.StartWell.Mat = "-";
                    }

                    if (dataTable.Columns.Contains("起始井基本问题"))
                    {
                        item.StartWell.Problem = dataTable.Rows[i]["起始井基本问题"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.StartWell.Problem))
                    {
                        item.StartWell.Problem = "-";
                    }

                    item.EndWell = new WellEntity();
                    if (dataTable.Columns.Contains("终止井号"))
                    {
                        item.EndWell.No = dataTable.Rows[i]["终止井号"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.EndWell.No))
                    {
                        item.EndWell.No = "-";
                    }

                    if (dataTable.Columns.Contains("终止井类型"))
                    {
                        item.EndWell.Type = dataTable.Rows[i]["终止井类型"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.EndWell.Type))
                    {
                        item.EndWell.Type = "-";
                    }

                    if (dataTable.Columns.Contains("终止井功能类型"))
                    {
                        item.EndWell.FuncType = dataTable.Rows[i]["终止井功能类型"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.EndWell.FuncType))
                    {
                        item.EndWell.FuncType = "-";
                    }
                    if (dataTable.Columns.Contains("终止井材质"))
                    {
                        item.EndWell.Mat = dataTable.Rows[i]["终止井材质"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.EndWell.Mat))
                    {
                        item.EndWell.Mat = "-";
                    }

                    if (dataTable.Columns.Contains("终止井基本问题"))
                    {
                        item.EndWell.Problem = dataTable.Rows[i]["终止井基本问题"].ToString();
                    }
                    if (string.IsNullOrEmpty(item.EndWell.Problem))
                    {
                        item.EndWell.Problem = "-";
                    }

                    if (item.StartWell.No != null && item.StartWell.No.Length >= 4)
                    {
                        item.Type = item.StartWell.No.Substring(2, 2);
                    }
                    if (dataTable.Columns.Contains("管段材质"))
                    {
                        item.Mat = dataTable.Rows[i]["管段材质"].ToString();
                    }
                    if (dataTable.Columns.Contains("检测方法"))
                    {
                        item.Method = dataTable.Rows[i]["检测方法"].ToString();
                    }
                    if (dataTable.Columns.Contains("检测方向"))
                    {
                        item.Direction = dataTable.Rows[i]["检测方向"].ToString();
                    }
                    if (dataTable.Columns.Contains("检测长度"))
                    {
                        item.Length = dataTable.Rows[i]["检测长度"].ToString();
                    }
                    if (dataTable.Columns.Contains("检测日期"))
                    {
                        item.Date = dataTable.Rows[i]["检测日期"].ToString();
                    }
                  

                    if (dataTable.Columns.Contains("缺陷坐标"))
                    {
                        item.Position = dataTable.Rows[i]["缺陷坐标"].ToString();
                    }
                    dataList.Add(item);
                }
            }
            return (dataList,result.PicList);
        }
        /// <summary>
        /// 获取环向
        /// Excel内部是9-10m,1h~10h格式
        /// h为环向信息，要转成0110格式
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public string GetCircleDirection(string val)
        {
            if (string.IsNullOrEmpty(val) || val.IndexOf('h')<0)
                return "";
            val = val.Replace("，", ",").Replace("～", "~");
            var tmp = val.Split(',')[1];
            var array = tmp.Split('~');
            if (array.Length == 1)
            {
                return array[0].TrimEnd('h').PadLeft(2, '0');
            }
            else {
                return $"{ array[0].TrimEnd('h').PadLeft(2, '0')}{ array[1].TrimEnd('h').PadLeft(2, '0')}";
            }

        }
        /// <summary>
        /// 通过缺陷代码获取缺陷类型
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetDefectTypeByCode(string code)
        {
            switch (code)
            {
                case "PL":
                case "BX":
                case "FS":
                case "CK":
                case "QF":
                case "TJ":
                case "TL":
                case "AJ":
                case "CR":
                case "SL":
                    return "结构性";
                case "CJ":
                case "JG":
                case "ZW":
                case "CQ":
                case "SG":
                case "FZ":
                    return "功能性";
                default:
                    return "";
            }
        }
        /// <summary>
        /// 通过缺陷代码获取缺陷名称
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetDefectNameByCode(string code)
        {
            switch (code)
            {
                case "PL":
                    return "破裂";
                case "BX":
                    return "变形";
                case "FS":
                    return "腐蚀";
                case "CK":
                    return "错口";
                case "QF":
                    return "起伏";
                case "TJ":
                    return "脱节";
                case "TL":
                    return "接口材料脱落";
                case "AJ":
                    return "支管暗接";
                case "CR":
                    return "异物穿入";
                case "SL":
                    return "渗透";
                case "CJ":
                    return "沉积";
                case "JG":
                    return "结垢";
                case "ZW":
                    return "障碍物";
                case "CQ":
                    return "残墙,坝根";
                case "SG":
                    return "树根";
                case "FZ":
                    return "浮渣";
                default:
                    return "";
            }
        }
        private string DistinguishReulst(byte[] imageBytes)
        {
            //imageStr图片二进制字符串
            return "{\"Name\":\"障碍物\",\"Level\":2}";
        }

        /// <summary>
        /// 获取当前选中的ExcelItem
        /// </summary>
        /// <returns></returns>
        public WorkSpaceEntity GetCurExcelItem() {
            return this.Data.ExcelList.Where(a => a.BorderBackground == "#0087D3").FirstOrDefault();
        }

        #region Command
        public RelayCommand<object> TabSwitch { get; private set; }
        public RelayCommand AddExcel { get; private set; }
        public RelayCommand DelExcel { get; private set; }

        public RelayCommand<object> ToReview { get; private set; }
        public RelayCommand Delete { get; private set; }
        public RelayCommand BatchDistinguish { get; private set; }

        public RelayCommand<object> CheckBoxClick { get; private set; }
        #endregion

        #region 数据绑定
        public AIReviewEntity Data { get; private set; }

        private DataList selectedItem;
        public DataList SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                selectedItem = value;
                RaisePropertyChanged();
            }
        }

        #region 数据绑定辅助方法
        /// <summary>
        /// excel列表
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ObservableCollection<WorkSpaceEntity> InitExcelList(List<WorkSpaceEntity> list)
        {
            ObservableCollection<WorkSpaceEntity> result = new ObservableCollection<WorkSpaceEntity>();
            if (list == null || list.Count < 1) {
                this.Data.DataListList = new ObservableCollection<DataList>();
                return result;
            }
            for (int i = 0; i < list.Count; i++)
            {
                //默认选中第0个
                if (i == 0)
                {
                    list[i].CornerRadius = "15 15 0 0";
                    list[i].ImageSrcConLeft = $"{imgSrc}dcl11.png";
                    list[i].ImageSrcConRight = $"{imgSrc}dcl99.png";
                    list[i].BorderBackground = "#0087D3";
                    list[i].LabelForeground = "#FFFFFF";
                    if (StaticCache.AiDic.ContainsKey(list[i].Id)) {
                        this.Data.DataListList = new ObservableCollection<DataList>(StaticCache.AiDic[list[i].Id]);
                    }
                }
                else
                {
                    list[i].CornerRadius = "0";
                    list[i].ImageSrcConLeft = $"{imgSrc}dcl1.png";
                    list[i].ImageSrcConRight = $"{imgSrc}dcl9.png";
                    list[i].BorderBackground = "Transparent";
                    list[i].LabelForeground = "#7C8288";
                }
                result.Add(list[i]);
            }
            return result;
        }
        #endregion
        #endregion
    }
}
